<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <title>无标题文档</title>
    <link rel="stylesheet" href="css/login.css"/>

    <script src="plugins/jquery/dist/jquery.min.js"></script>
    <script src="plugins/healthmobile.js"></script>
    <script src="plugins/vue/axios-0.18.0.js"></script>

    <script src="../plugins/vue/vue.js"></script>
    <link rel="stylesheet" href="../plugins/element-ui/lib/theme-chalk/index.css"/>
    <script src="../plugins/element-ui/lib/index.js"></script>

</head>

<body>
<div id="app">

    <div class="login">

        <div class="top-header">
            <span class="center">传&nbsp;智&nbsp;健&nbsp;康</span>
        </div>

        <div class="welcome"><img src="images/welcome.png"></div>

        <div class="login-form">

            <form class="login-form">

                <div class="login-inp">
                    <label>手机号</label>
                    <input v-model="member.telephone" type="text" name="telephone" placeholder="请输入手机号">
                </div>

                <div class="login-inp2">
                    <label>验证码</label>
                    <input v-model="member.validateCode" type="text" name="validateCode" placeholder="请输入验证码">
                </div>

                <div class="login-inp3">
                    <input id="validateCodeButton" @click="sendValidateCode()" type="button" value="发送验证码">
                </div>

            </form>

            <div class="login-inp">
                <input @click="submitMember()" class="login-input" type="submit" value="立即登录">
            </div>

        </div>

        <div class="login-txt">
            <a href="#">立即注册</a>|
            <a href="#">忘记密码？</a>|
            <a href="login.html">账号密码登录</a>
        </div>


    </div>
    <div style="text-align:center;">
    </div>

</div>
</body>

<script>
    var vue = new Vue({
        el:'#app',
        data:{

            member:{}

        },
        methods:{

            //发送验证码
            sendValidateCode() {
                //获取用户输入的手机号码
                var telephone = this.member.telephone;
                //校验手机号输入是否正确
                if (!checkTelephone(telephone)) {
                    this.$message.error("请输入正确的手机号");
                    return false;
                }
                validateCodeButton = $("#validateCodeButton")[0];
                clock = window.setInterval(doLoop, 1000);//一秒执行一次

                axios.post("/validateCode/send4Login.do?telephone=" + telephone).then((response) => {
                    if (!response.data.flag) {
                        //验证码发送失败
                        this.$message.error('验证码发送失败，请检查手机号输入是否正确')
                    }
                });
            },

            submitMember() {

                //发送ajax请求，提交表单数据到后台进行业务处理
                axios.post("/login/loginByValidateCode.do", this.member).then((res) => {
                    if (res.data.flag) {
                        //预约成功，跳转到成功页面
                        window.location.href = "/pages/index.html";
                    } else {
                        //预约失败，提示信息
                        this.$message.error(res.data.message);
                    }
                });
            }

        }
    });
</script>

</html>
